;;;Makes XREF paths relative if possible.
;;;
;;;	Author:
;;;		Henry C. Francis
;;;		425 N. Ashe St.
;;;		Southern Pines, NC 28387
;;;
;;;	All rights reserved.
;;;
;;;	Copyright:  
;;;	   Edited:  
(defun c:xrpath (/)
  (setq blk_def nil
	xrlst_in nil
	xrlst_out nil
	line_in nil
	ex_xr_lst nil
  )
  (setq blk_lst nil)
  (setq blk_def (tblnext "block" T))
  (if (assoc 1 blk_def)
    (setq
      blk_lst (list
		(list (cdr (assoc 2 blk_def)) (cdr (assoc 1 blk_def)))
	      ) ;_ end of list
    ) ;_ end of setq
  ) ;_ end of if
  (while (setq blk_def (tblnext "block"))
    (if	(assoc 1 blk_def)
      (if blk_lst
	(setq blk_lst (append (list (list (cdr (assoc 2 blk_def))
					  (cdr (assoc 1 blk_def))
				    ) ;_ end of list
			      ) ;_ end of list
			      blk_lst
		      ) ;_ end of append
	) ;_ end of setq
	(setq blk_lst (list (list (cdr (assoc 2 blk_def))
				  (cdr (assoc 1 blk_def))
			    ) ;_ end of list
		      ) ;_ end of list
	) ;_ end of setq
      ) ;_ end of if
    ) ;_ end of if
  ) ;_ end of while
  (while (member '(nil) blk_lst)
    (setq blk_lst (cdr (member '(nil) blk_lst)))
  ) ;_ end of while
  (if blk_lst
    (foreach n blk_lst
      (COND
	((wcmatch (strcase (cadr n))
		  (strcase (strcat (getvar "dwgprefix") "*"))
	 ) ;_ end of wcmatch
	 (progn
	   (if (findfile
		 (substr (cadr n) (1+ (strlen (getvar "dwgprefix"))))
	       ) ;_ end of findfile
	     (command
	       ".xref"
	       "path"
	       (car n)
	       (substr (cadr n) (1+ (strlen (getvar "dwgprefix"))))
	     ) ;_ end of command
	   ) ;_ end of if
	   (princ "\n")
	   (princ (cadr n))
	   (princ "\t")
	   (princ (substr (cadr n) (1+ (strlen (getvar "dwgprefix")))))
	   (setq do_qsave T)
	 ) ;_ end of progn
	 (progn
	   (princ "\n")
	   (princ (strcase (cadr n)))
	   (princ "\t")
	   (princ (strcase (getvar "dwgprefix")))
	 ) ;_ end of progn
	)
	((wcmatch (substr (getvar "dwgprefix")
			  1
			  (1- (strlen (getvar "dwgprefix")))
		  ) ;_ end of substr
		  "*\\*"
	 ) ;_ end of wcmatch
	 (progn
	   (setq bck_cnt (1- (strlen (getvar "dwgprefix"))))
	   (setq fn_prefix "..")
	   (setq done_pathopts nil)
	   (while (and (not done_pathopts) (> bck_cnt 3))
	     (while
	       (not
		 (wcmatch (substr (getvar "dwgprefix") 1 bck_cnt) "*\\")
	       ) ;_ end of not
		(setq bck_cnt (1- bck_cnt))
	     ) ;_ end of while
	     (if
	       (wcmatch
		 (strcase (cadr n))
		 (strcat
		   (substr (strcase (getvar "dwgprefix")) 1 bck_cnt)
		   "*"
		 ) ;_ end of strcat
	       ) ;_ end of wcmatch
		(if
		  (findfile (strcat fn_prefix (substr (cadr n) bck_cnt)))
		   (progn
		     (command ".xref"
			      "path"
			      (car n)
			      (strcat fn_prefix (substr (cadr n) bck_cnt))
		     ) ;_ end of command
		     (setq done_pathopts T)
		   ) ;_ end of progn
		   (progn
		     (princ "\n")
		     (princ (strcat fn_prefix (substr (cadr n) bck_cnt)))
		   ) ;_ end of progn
		) ;_ end of if
	     ) ;_ end of if
	     (princ "\n")
	     (princ (car n))
	     (princ "\t")
	     (princ (strcat fn_prefix (substr (cadr n) bck_cnt)))
	     (setq do_qsave T)
	     (setq bck_cnt (1- bck_cnt))
	     (setq fn_prefix (strcat fn_prefix "\\.."))
	   ) ;_ end of while
	 ) ;_ end of progn
	)
      ) ;_ end of COND
;;;	(wcmatch (strcase (cadr n)) "W:\\1363\\28396\\*")
;;;	(princ (strcase (cadr n)))
      (if (member (strcase (cadr n)) ex_xr_lst)
	nil
	(setq ex_xr_lst (append (list (strcase (cadr n))) ex_xr_lst))
      ) ;_ end of if
    ) ;_ end of foreach
  ) ;_ end of if
  (if ex_xr_lst
    (progn
      (setq ex_xr_lst (acad_strlsort ex_xr_lst))
    ) ;_ end of progn
  ) ;_ end of if
;;;    (mapcar
;;;      '(lambda (x) (princ(strcat"\n" x)))
;;;       blk_lst
;;;    );mapcar
  (if (member "W:\\8241\\24181\\0CAD\\SURVEY\\PROP_P1.DWG"
	      ex_xr_lst
      ) ;_ end of member
    (command ".xref" "path" "prop_p1" "Survey\\prop_p1")
  ) ;_ end of if
  (if (member "W:\\8241\\24181\\0CAD\\CSTECX03.DWG" ex_xr_lst)
    (command ".xref" "path" "cstecx03" "cstecx03")
  ) ;_ end of if
  (if (member "W:\\8241\\24181\\0CAD\\SURVEY\\NAMES_P1.DWG"
	      ex_xr_lst
      ) ;_ end of member
    (command ".xref" "path" "names_p1" "Survey\\names_p1")
  ) ;_ end of if
  (if do_qsave
    (progn
      (c:qsave)
      (setq do_qsave nil)
    ) ;_ end of progn
  ) ;_ end of if
  (princ)
) ;_ end of defun
